import { Injectable, Inject } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Quote } from '../domain/quote.model';
import { HttpClient } from '@angular/common/http';

@Injectable()
export class QuoteService {

  constructor(private http: HttpClient,
    @Inject('BASE_CONFIG') private config) { }

  getQuote(): Observable<Quote> {
    const url = `${this.config.uri}/quotes/${Math.floor(Math.random() * 10)}`;
    return this.http.get<Quote>(url).debug('Quote：');
    // 相当于 http 4.5以下 的
    // return this.http.get(url)
  }
}
